Imports System.IO
Imports System.Xml.Serialization
Imports System.Collections.Generic
Imports Microsoft.Office.Interop


Public Class SyncedItemsList
    Inherits List(Of SyncItem)


    Public Shadows Sub Add(ByVal item As SyncItem)
        'check to see if there is an item with the same key
        'Dim results = From aSyncItem In Me Where aSyncItem.Name = item.Name
        'If results.Count > 0 Then
        '    Me.Remove(results(0))
        'End If
        For i As Integer = 0 To Me.Count - 1 Step 1
            If CType(Me(i), SyncItem).OutlookId = item.OutlookId OrElse CType(Me(i), SyncItem).TaskSeriesId = item.TaskSeriesId Then
                'replace old item
                Me(i) = item
                Exit Sub
            End If
        Next
        'was not found, so add new 
        MyBase.Add(item)
    End Sub

    Public Overloads Function Contains(ByVal TaskSeriesId As String, ByVal TaskId As String)
        'todo should i check by list id as well?, will this work for recurrence?
        Dim results = From item In Me Where item.TaskId = TaskId AndAlso item.TaskSeriesId = TaskSeriesId
        If results.Count > 0 Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Overloads Function Contains(ByVal OutlookTask As Outlook.TaskItem) As Boolean
        Dim results = From item In Me Where item.OutlookId = OutlookTask.EntryID
        If results.Count > 0 Then
            Return True
        Else
            Return False
        End If
    End Function
End Class